<%--
  Created by IntelliJ IDEA.
  User: zhao
  Date: 17-1-24
  Time: 上午10:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑文章</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/easyui/jquery.min.js"></script>
    <!--建议手动加在语言，避免在ie下有时因为加载语言失败导致编辑器加载失败-->
    <!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型，比如你在配置项目里配置的是英文，这里加载的中文，那最后就是中文-->
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/ueditor.all.min.js"> </script>
    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/ueditor/lang/zh-cn/zh-cn.js"></script>

    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/easyui/jquery.easyui.min.js"></script>

    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/easyui/themes/default/easyui.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/resource/easyui/themes/icon.css">

    <script type="text/javascript" src="${pageContext.request.contextPath}/resource/js/common.js"></script>

    <script type="text/javascript" charset="utf-8" src="${pageContext.request.contextPath}/resource/jquery.form.min.js"></script>

    <script type="text/javascript">
        //编辑器
        var ue = null;
        $(function () {
            ue = UE.getEditor('editor');
            ue.addListener("ready", function () {
                // editor准备好之后才可以使用
                ue.setContent('${news.content}');

            });
            //加载需要被修改news内容
            $('#id').val('${news.id}');
            $('#title').val('${news.title}');
            $('#newsDate').datebox('setValue','${news.date}');
            $('#author').val('${news.author}');
            $('#intrduce').val('${news.intrduce}');
            $('#module').combobox('select','${news.module.id}');
            $('#thumbnailPath').val('${news.thumbnailPath}');
        });

        //提交表单
        function formSave() {
            //判断编辑器是否有内容
//            $('#form').submit();
            if (UE.getEditor('editor').hasContents()){
                var content = UE.getEditor('editor').getContent();
                //有内容 提交
                $('#newsContent').val(content);


                $('#form').submit();


            }else{
                //无内容
                $.messager.alert('警告','请输入内容');
            }
        }
        //表单重置
        function formReset() {

        }

    </script>
</head>
<body>

<div>


    <form id="form" enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath}/admin/news/editNews.do">
        <table width="100%">
            <tr style="width: 100%;">
                <td style="width: 50px;">
                    标题
                </td>
                <td>
                    <input id="title" name="title" style="width:100%;" ></input>
                </td>
            </tr>
            <tr>
                <td>
                    简介
                </td>
                <td>
                    <input id="intrduce" name="intrduce"  style="width:100%"></input>
                </td>
            </tr>
            <tr>
                <td>
                    作者
                </td>
                <td>
                    <input id="author"  name="author"  style="width:100%"></input>
                </td>
            </tr>
            <tr>
                <td>模块</td>
                <td>
                    <select id="module" name="module.id" style="width:200px;"></select>
                </td>
            </tr>
            <tr>
                <td>缩略图</td>
                <td>
                    <input id="fbz"  name="file" type="file" style="width:300px">
                </td>
            </tr>
        </table>
        <input id="newsContent" name="content" type="hidden">
        <input id="id" name="id" type="hidden">
        <input id="thumbnailPath" name="thumbnailPath" type="hidden">
        <div style="width:100%;">
            <script id="editor" type="text/plain" style="width:100%;height:250px;"></script>
            <script type="text/javascript">

            </script>
        </div>
        <div style="text-align: right">
            <a class="easyui-linkbutton" data-options="iconCls:'icon-reload'" onclick="formReset()">重置</a>
            <a class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="formSave()">保存</a>
            选择发布时间:<input id="newsDate" name="date">
        </div>
        <script type="text/javascript">
            $('#module').combobox({
                url:'/module/moduleJson.do',
                valueField:'id',
                textField:'name'
            });
            $('#fb').filebox({
                buttonText: '选择缩略图',
                buttonAlign: 'left'
            });
            $('#newsDate').datebox({
                requested:true
            })

        </script>
    </form>
</div>

</body>
</html>
